package com.jxpanda.spring.module.auth.core.token;

import com.jxpanda.spring.module.auth.core.authentication.token.UserDetailsAuthenticationToken;
import com.jxpanda.spring.module.auth.endpoint.OAuth2Request;
import lombok.Getter;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.oauth2.jwt.JwsHeader;
import org.springframework.security.oauth2.jwt.JwtClaimsSet;
import org.springframework.security.oauth2.jwt.JwtEncoderParameters;

@Getter
public class ReactiveJwtEncodingContext<U extends UserDetails> {

    private final JwsHeader.Builder header;

    private final JwtClaimsSet.Builder claims;

    private final OAuth2Request oAuth2Request;

    private final UserDetailsAuthenticationToken<U> authenticationToken;

    private final U userDetails;

    public ReactiveJwtEncodingContext(JwsHeader.Builder header, JwtClaimsSet.Builder claims, UserDetailsAuthenticationToken<U> authenticationToken) {
        this.header = header;
        this.claims = claims;
        this.authenticationToken = authenticationToken;
        this.oAuth2Request = authenticationToken.getOAuth2Request();
        this.userDetails = authenticationToken.getUserDetails();
    }

    public JwtEncoderParameters build() {
        return JwtEncoderParameters.from(this.header.build(), this.claims.build());
    }

}
